package com.example.producerconsumer;

/**
 * @version 1.0.0
 * @className: Producter
 * @description: 生产者
 * @author: rosszhang
 * @date: 2022/5/13 14:15
 */
public class Producter implements Runnable {
    private SyncStack syncStack;

    public Producter(SyncStack syncStack) {
        this.syncStack = syncStack;
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        for (int i = 0; i < syncStack.pro().length; i++) {
            String productor = "产品：" + i;
            syncStack.push(productor);
            System.out.println("生产了："+productor);

            try {
                Thread.sleep(200);
            }catch (InterruptedException e){
                e.printStackTrace();
            }

        }
    }
}
